import router from "../router";
import index from "../views/index";

// 这个文件是设置动态路由的
// permissions是一个资源的数组
export function activeRouter(permissions) {
  //console.log(permissions)
  const userStr = sessionStorage.getItem("user")
  if (permissions) {
    //const user = JSON.parse(permissions)
    let root = {
      path: '/index',
      name: '首页',
      component: index,
      iconCls: 'el-icon-tickets',
      children: []
    }
    permissions.forEach(p => {
      let obj = {
        path: p.path,
        name: p.name,
        component: () => import("@/views/" + p.name)
      };
      root.children.push(obj)
      //console.log(p)
    })

    router.addRoute(root)

  }
}
